package person.csx.studentgradle.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import person.csx.studentgradle.dao.StudentDao;
import person.csx.studentgradle.model.Student;

import person.csx.studentgradle.service.StudentService;

import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class StudentServiceImpl     implements StudentService{
    @Autowired
    private StudentDao studentDao;

    @Override
    public List<Student> list() {
        return studentDao.selectList(null);
    }

    @Override
    public int delete(int id) {
        return studentDao.deleteById(id);
    }

    /**
     * 新增学生
     * @param student
     * @return
     */
    @Override
    public int insert(Student student) {
        return studentDao.insert(student);
    }

    @Override
    public List<Student> selectByPage(int currPage, int pageSize) {
        //从第几条记录返回数据
        int  fromIndex=(currPage<=0)?0:(currPage-1)*pageSize;
        //调用分页dao方法
        return studentDao.selectByPage(fromIndex,pageSize);
    }

    @Override
    public int checkOnlyByName(String name) {
       List<Student> students=studentDao.checkOnlyByName(name);
       return students.size();
    }

    @Override
    public int checkOnlyById(String id){
        List<Student> students=studentDao.checkOnlyById(id);
        return students.size();
    }
}




